<?php

namespace App\Job\YunXin;


use App\Utils\LoggerUtil;
use Hyperf\AsyncQueue\Job;
use Throwable;

/**
 * Note - 刷新用户在线状态队列
 * DateTime 2024/7/30 12:26
 * User Admin
 * Class YunXinUserOnlineStatusJob
 * @package App\Job\YunXin
 */
class YunXinUserOnlineStatusJob extends Job
{

    private mixed $params;

    public function __construct($params)
    {
        // 这里最好是普通数据，不要使用携带 IO 的对象，比如 PDO 对象
        $this->params = $params;
    }

    public function handle()
    {
        // TODO: Implement handle() method.
        $this->job($this->params);

    }

    private function job(mixed $origin)
    {
        try {
            $body = json_decode($origin, true);
            LoggerUtil::write("user_online_status_queue_job", $body);
            $fromUid = $body['fromUid'];
            $toUids = $body['toUids'];
            $message = $body['message'];
            $rs = (new \App\Services\YunXinCloud\WyyClient())->sendBatchUserOlineStatusMsg($fromUid, $toUids, $message);
            if (!$rs) {
                LoggerUtil::write("user_online_status_queue_job", "发送失败");
            } else {
                LoggerUtil::write("user_online_status_queue_job", "发送成功");
            }
        } catch (Throwable $e) {
            LoggerUtil::write("user_online_status_queue_job", [
                "message" => $e->getMessage(),
                "file" => $e->getFile(),
                "line" => $e->getLine(),
            ]);
        }

    }
}